import  math
import sys

def iou_wh(w1,h1,w2,h2):
    inter=min(w1,w2)*min(h1,h2)
    union=w1*h1+w2*h2-inter
    return inter/(union+1e-6)

def parse_input():

    #检测框个数，聚类中心个数，聚类迭代个数
    N,K,T=map(int,input().split())
    pts=[list(map(int,input().split())) for _ in range(N)]
    return N,K,T,pts

def kmeans_iou(N,K,T,boxes):
    #initi
    centers=[boxes[i] for i in range(K)]
    for _ in range(T):#聚类迭代个数
        clusters=[[] for _ in range(K)]
        #分配阶段
        for (w,h) in boxes:
            best_id=0
            best_dist=float('inf')
            for idx,(cw,ch) in enumerate(centers):
                d=1.0-iou_wh(w,h,cw,ch)
                if d<best_dist:
                    best_dist=d
                    best_id=idx
            clusters[best_id].append((w,h))

        #更新阶段
        changed=False
        new_centers=[]
        for idx in range(K):
            if clusters[idx]:
                sw=sum(x for x,_ in clusters[idx])#求和
                sh=sum(y for _,y in clusters[idx])
                nw=math.floor(sw/len(clusters[idx]))
                nh=math.floor(sh/len(clusters[idx]))

                if (nw,nh)!=centers[idx]:
                    changed=True
                new_centers.append((nw,nh))

            else:
                new_centers.append([idx])

        centers=new_centers

        if not changed:
            break

    centers.sort(key=lambda wh:(wh[0]*wh[1],wh[0],wh[1]),reverse=True)
    return centers

def main():

    N,K,T,boxes=parse_input()
    centers=kmeans_iou(N,K,T,boxes)
    out_lines=["{} {}".format(w,h) for w,h in centers]
    print("\n".join(out_lines))

if __name__ == '__main__':
    main()


























